﻿//********************************************************************************//
//创建日期：<创建日期，2016-03-31>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：处理账单相关
//********************************************************************************//
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Entity;
using YXYLCommon;
using System.Web;
using System.Web.SessionState;

namespace Web.ashx.YSSF
{
    public class ZhangDan : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int? rsno = -1;
            string rsmsg = "";
            if (context.Request["op"] == "ZDXX")
            {
                int type = int.Parse(context.Request["type"]);
                string yonghuh = context.Request["yhh"];
                int sffs = int.Parse(context.Request["sffs"]);
                int y1 = int.Parse(context.Request["y1"]);
                int y2 = int.Parse(context.Request["y2"]);
                List<YSSFZhangDanXX> list = new DALYSSFZhangDanXX().Get(type, yonghuh, y1, y2,sffs);
                context.Response.Write(JsonConvert.SerializeObject(list));
            }           
            else if (context.Request["op"] == "YDLIST")
            {
                int zt = int.Parse(context.Request["zt"]);
                int ym = int.Parse(context.Request["ym"]);
                string hm = context.Request["hm"];
                DbDateTime printdate = DbDateTime.Parse(context.Request["printdate"]);
                List<YSSFZhangDanXX> list = new DALYSSFZhangDanXX().Get2(zt, ym, hm, printdate);
                context.Response.Write(JsonConvert.SerializeObject(list));
            }
            else if (context.Request["op"] == "DYZTBG")//已打发票变更打印状态 成功与打坏的切换
            {
                //获取打印状态,账单编号,发票号码,用户号,用户名,开户户名
                int dyzt = int.Parse(context.Request["dyzt"]);
                string fphms = context.Request["fphms"];
                DbCmdResult dbrs = new DALYSSFZhangDanXX().DaYinZTBG(dyzt, fphms);
                context.Response.Write(JsonConvert.SerializeObject(new JsonRs(dbrs.IsSuccess, dbrs.ReturnMsg, dbrs.ReturnMsg.Split('|')[0])));
            }
            else if (context.Request["op"] == "DYTJ")
            {
                DbDateTime printdate = DbDateTime.Parse(context.Request["printdate"]);
                List<QSSFZhangDanDYTJ> list = new DALYSSFZhangDanXX().DaYinTJGet(printdate);
                context.Response.Write(JsonConvert.SerializeObject(list));
            }
            else if (context.Request["op"] == "DY")
            {
                //获取打印状态,账单编号,发票号码,用户号,用户名,开户户名
                string dyzt = context.Request["dyzt"];
                string sffs = context.Request["sffs"];
                string zdbh = context.Request["zdbh"];
                string fphm = context.Request["fphm"];
                string yhh = context.Request["yhh"];
                string yhm = context.Request["yhm"];
                string khhm = context.Request["khhm"];
                //成功:1 打坏:2
                DbCmdResult dbrs = new DALYSSFZhangDanXX().DY(dyzt == "success" ? 1 : 2,int.Parse(sffs), int.Parse(zdbh), fphm, yhh, yhm, khhm, DbDateTime.Parse(DateTime.Now), LoginInfo.CurrentUser.UserID, LoginInfo.CurrentUser.UserName);
                context.Response.Write(JsonConvert.SerializeObject(new JsonRs(dbrs.IsSuccess, dbrs.ReturnMsg, dbrs.ReturnMsg)));
                //JsonRs rs = new JsonRs(rsno == 1, rsmsg, null);
                //context.Response.Write(JsonConvert.SerializeObject(rs));
            }
            else if (context.Request["op"] == "QFXX_HJ")
            {
                string yhh = context.Request["yhh"];
                DXSQianFeiXX obj = new DALYSQFSFXX().GetQFHJ(yhh);
                JsonRs rs = new JsonRs();
                rs.Data1 = obj;
                rs.State = obj.IsExists;
                context.Response.Write(JsonConvert.SerializeObject(rs));
            }
            else if (context.Request["op"] == "QFXX_MX")
            {
                string yhh = context.Request["yhh"];
                context.Response.Write(JsonConvert.SerializeObject(new DALYSQFSFXX().GetQFMX(yhh)));
            }
            else if (context.Request["op"] == "SF_ZPXJFW")
            {
                string sfbh = context.Request["sfbh"];
                string zdbh = context.Request["zdbh"];
                decimal sfje = Convert.ToDecimal(context.Request["sfje"]);
                int zwym = int.Parse(context.Request["sfrq"]);
                int type = int.Parse(context.Request["type"]);
                DbCmdResult dbrs = new DALYSQFSFXX().DBSF(sfbh,zdbh, sfje,zwym, type, LoginInfo.CurrentUser.UserID.ToString());
                JsonRs rs = new JsonRs(dbrs.IsSuccess, dbrs.ReturnMsg, null);
                context.Response.Write(JsonConvert.SerializeObject(rs));
            }
            else if (context.Request["op"] == "SFBHHQ")
            {
                context.Response.Write(new DALYSQFSFXX().GetDANGQIANSFBH());
            }
            else if (context.Request["op"] == "SFXX_MX")
            {
                string zwym = context.Request["zwym"];
                string sfrq = context.Request["sfrq"];
                string yhh = context.Request["yhh"];
                List<DXSShouFeiXX> list = new DALYSQFSFXX().GetSFMX(string.IsNullOrEmpty(zwym) ? -1 : int.Parse(zwym), string.IsNullOrEmpty(sfrq) ? null : (DateTime?)Convert.ToDateTime(sfrq), yhh);
                context.Response.Write(JsonConvert.SerializeObject(list));
            }
            else if (context.Request["op"] == "SFXX_QX")
            {
                string ids = context.Request["ids"];
                string zdbhs = context.Request["zdbhs"];
                DbCmdResult dbrs = new DALYSQFSFXX().SFQX(ids, zdbhs, LoginInfo.CurrentUser.UserID.ToString());
                JsonRs rs = new JsonRs(dbrs.IsSuccess, dbrs.ReturnMsg, null);
                context.Response.Write(JsonConvert.SerializeObject(rs));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}